package com.shop.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
	private static  Session session;
	private static SessionFactory sessionFactory;
	static{
		StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
				.configure() // configures settings from hibernate.cfg.xml
				.build();
		Configuration config = new Configuration();
		sessionFactory = config.buildSessionFactory(registry);
	}
	public static Session getSesssion(){
		session = sessionFactory.openSession();	
		return session;
	}
	
	public static void closeSession(Session session){
		if(session!=null){
			session.close();
		}
		if(sessionFactory!=null){
			sessionFactory.close();
		}
	}
	
}
